package com.ibeeking.found.file.rest.service.office.mappers;

import com.ibeeking.found.file.rest.service.office.entities.UserEntity;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Component
@Primary
public class UsersMapper extends AbstractMapper<UserEntity, com.ibeeking.found.file.rest.service.office.documentserver.models.filemodel.User> {
    @Resource
    private ModelMapper mapper;

    public UsersMapper(){
        super(com.ibeeking.found.file.rest.service.office.documentserver.models.filemodel.User.class);
    }

    @PostConstruct
    public void configure() {  // configure the users mapper
        mapper.createTypeMap(UserEntity.class, com.ibeeking.found.file.rest.service.office.documentserver.models.filemodel.User.class)  // create the type map
                .setPostConverter(modelConverter());  // and apply the post converter to it
    }

    @Override
    public void handleSpecificFields(UserEntity source, com.ibeeking.found.file.rest.service.office.documentserver.models.filemodel.User destination) {  // handle specific users fields
//        destination.setGroup(source.getGroup() != null ? source.getGroup().getName() : null);  // set the GroupEntity parameter
    }
}
